package com.example.user.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.commons.filter.RequestFilter;
import com.example.commons.response.ResponseResult;
import com.example.commons.response.ResultCode;
import com.example.user.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/account/business")
@CrossOrigin(value = "*")
public class UserController {
    @Autowired
    UsersService usersService;

    @PostMapping("/register")
    public ResponseResult register(RequestFilter requestFilter) {
        JSONObject bodyJson = requestFilter.getRequestBodyJson();
        //todo 此处应对请求体做加密解密处理
        usersService.register(bodyJson.getString("username"), bodyJson.getString("password"));
        return new ResponseResult(ResultCode.SUCCESS, null, null);
    }

    @PostMapping("/demo")
    public ResponseResult demo (){
        return new ResponseResult(ResultCode.SUCCESS,null,null);
    }
}
